﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonDto
{
    public class DefaultBaseResponse<TData> : BaseResponseDto<TData>
    {
        public static implicit operator DefaultBaseResponse<TData>(TData data) => new DefaultBaseResponse<TData>
        {
            Data = data,
            Code = "0",
            Message = "success",
            SubCode = string.Empty,
            SubMessage = string.Empty,
        };
        public static explicit operator TData(DefaultBaseResponse<TData> dto) => dto.Data;

        public override string ToString()
        {
            List<string> collection = new List<string>();
            if (string.IsNullOrWhiteSpace(Code) == false) collection.Add($"{nameof(Code)}: {Code}");
            if (string.IsNullOrWhiteSpace(Message) == false) collection.Add($"{nameof(Message)}: {Message}");
            if (string.IsNullOrWhiteSpace(SubCode) == false) collection.Add($"{nameof(SubCode)}: {SubCode}");
            if (string.IsNullOrWhiteSpace(SubMessage) == false) collection.Add($"{nameof(SubMessage)}: {SubMessage}");

            return string.Join("; ", collection);
        }
    }
}
